package com.mf.service.impl.pageConfig;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.bo.pageConfig.BasicJsonConfigBo;
import com.mf.entity.request.pageConfig.JsonConfigSearchReq;
import com.mf.mapper.BasicJsonConfigMapper;

import com.mf.service.pageConfig.IBasicJsonConfigService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.heollhai.common.utils.VerifyUtils;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
*  服务实现类
*
* @author mf
* @since 2024-12-19
*/
@Service
public class BasicJsonConfigServiceImpl extends ServiceImpl<BasicJsonConfigMapper, BasicJsonConfigBo> implements IBasicJsonConfigService {
    @Resource
    private BasicJsonConfigMapper jsonConfigMapper;

    @Override
    public Page<BasicJsonConfigBo> findPageList(JsonConfigSearchReq jsonConfigSearchReq) {
        Page<BasicJsonConfigBo> page = new Page<>(jsonConfigSearchReq.getPageNum(), jsonConfigSearchReq.getPageSize());
        LambdaQueryWrapper<BasicJsonConfigBo> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(jsonConfigSearchReq.getCname())) {
            queryWrapper.like(BasicJsonConfigBo::getCname, jsonConfigSearchReq.getCname());
        }

        if(VerifyUtils.isNotEmpty(jsonConfigSearchReq.getType())){
            queryWrapper.eq(BasicJsonConfigBo::getType, jsonConfigSearchReq.getType());
        }

        queryWrapper.orderByAsc(BasicJsonConfigBo::getCname)
                .orderByAsc(BasicJsonConfigBo::getSort);

        return jsonConfigMapper.selectPage(page, queryWrapper);
    }
}
